/*
 * @Author: zhangxiangsheng 1026583651@qq.com
 * @Date: 2024-06-24 13:41:38
 * @LastEditors: zhangxiangsheng 1026583651@qq.com
 * @LastEditTime: 2024-06-24 16:03:44
 * @FilePath: \appGly\pages\USearch\json.js
 * @Description:
 *
 * Copyright (c) 2024 by ${git_name_email}, All Rights Reserved.
 */
import store from "@/store/index";
let defaultValue = uni.$z.defaultValue;
const utypstr = defaultValue.utype.map((e) => {
  return e.value;
});

let userstore = store.state.user;
const searchjson = [
  { label: "用户名", value: "uUser" },
  { label: "联系人", value: "uxm" },
  { label: "联系电话", value: "utel" },
  {
    label: "用户类型",
    value: "sutype",
    type: "select",
    defaultValue: `utype in (${utypstr.toString()})`,
    option: [
      { label: "全部", value: `utype in (${utypstr.toString()})` },
      ...defaultValue.utype.map((e) => {
        return { label: e.label, value: `utype in (${e.value})` };
      }),
    ],
  },
  { label: "所属站点", value: "pcs", type: "pcs" },
];
const Uaddjson = [
  {
    value: "uUser",
    label: "用户名",
    rules: [
      {
        required: true,
        message: "请输入用户名",
        trigger: "blur",
      },
    ],
  },
  function ({ formData }) {
    const r = [];
    r.push({
      value: "dma",
      label: "密码",
      type: "password",
      rules: [
        {
          required: true,
          message: "请输入密码",
          trigger: "blur",
        },
        {
          validator(_rule, value, callback) {
            if (value && !isPassword(value)) {
              callback(new Error("密码格式不正确"));
            } else {
              callback();
            }
          },
          message: "密码应为6位以上，且不能全为数字或字母",
          trigger: ["blur"],
        },
        {
          message: "密码最少为6位",
          trigger: "blur",
          validator(_rule, value, callback) {
            if (value.length < 6) {
              callback(new Error("error"));
            } else {
              callback();
            }
          },
        },
      ],
    });
    function qrdma(value, callback) {
      if (formData.dma != value) {
        callback(new Error("error"));
      } else {
        callback();
      }
    }
    r.push({
      value: "qrdma",
      label: "确认密码",
      type: "password",
      rules: [
        {
          required: true,
          message: "请再次输入密码",
          trigger: "blur",
          validator(_rule, value, callback) {
            qrdma(value, callback);
          },
        },
      ],
    });

    return r;
  },
  {
    value: "utype",
    label: "用户类型",
    type: "select",
    option: [...defaultValue.utype],
    defaultValue: defaultValue.utype[0].value,
  },
  {
    value: "pcs",
    label: "所属站点",
    type: "pcs",

    defaultValue: userstore.USearch.pcs,
  },
  function ({ formData, propsdata }) {
    const r = [
      {
        value: "udj",
        label: "用户等级",
        type: "select",
        option: "udj",
        defaultValue: "1",
        if: {
          zhi: [{ value: "utype", zhi: ["11", "12", "0", "7", "15"] }],
        },
      },
    ];
    r[0].option = defaultValue.typeudjfn(formData, propsdata);
    if (r[0].option.length != 0) {
      r[0].defaultValue = r[0].option[0].value;
    }

    return r;
  },

  {
    value: "uxm",
    label: "联系人",

    rules: [
      {
        required: true,
        message: "请填写联系人",
        trigger: "blur",
      },
    ],
  },
  {
    value: "utel",
    label: "电话号码",

    rules: [
      {
        required: true,
        message: "请填写电话号码",
        trigger: "blur",
        validator(_rule, value, callback) {
          if (!test.mobile(value)) {
            callback(new Error("error"));
          } else {
            callback();
          }
        },
      },
    ],
  },
  function ({ formData }) {
    return formData.utel == ""
      ? []
      : [
          {
            value: "yzm",
            label: "验证码",
            type: "yzm",
            span: 24,
            rules: [
              {
                required: true,
                message: "请输入验证码",
                trigger: "blur",
              },
            ],
          },
        ];
  },
  {
    value: "bz",
    label: "备注",
  },
];
const Uedtjson = [
  {
    value: "uUser",
    label: "用户名",
    rules: [
      {
        required: true,
        message: "请输入用户名",
        trigger: "blur",
      },
    ],
    attrs: { disabled: true },
  },

  {
    value: "utype",
    label: "用户类型",
    type: "select",
    option: [...defaultValue.utype],
    defaultValue: defaultValue.utype[0].value,
  },
  {
    value: "pcs",
    label: "所属站点",
    type: "pcs",

    defaultValue: userstore.USearch.pcs,
  },
  function ({ formData, propsdata }) {
    const r = [
      {
        value: "udj",
        label: "用户等级",
        type: "select",
        option: "udj",
        defaultValue: "1",
        if: {
          zhi: [{ value: "utype", zhi: ["11", "12", "0", "7", "15"] }],
        },
      },
    ];
    r[0].option = defaultValue.typeudjfn(formData, propsdata);
    if (r[0].option.length != 0) {
      r[0].defaultValue = r[0].option[0].value;
    }

    return r;
  },

  {
    value: "uxm",
    label: "联系人",
  },
  {
    value: "utel",
    label: "电话号码",
  },
  function ({ formData, propsdata }) {
    return formData.utel == "" || formData.utel == propsdata.utel
      ? []
      : [
          {
            value: "yzm",
            label: "验证码",
            type: "yzm",
            span: 24,
            rules: [
              {
                required: true,
                message: "请输入验证码",
                trigger: "blur",
              },
            ],
          },
        ];
  },
  {
    value: "bz",
    label: "备注",
  },
];

const Udmaedt = [
  { label: "用户名", value: "uUser", type: "button" },
  {
    label: "旧密码",
    value: "olddma",
    type: "password",
    rules: [
      {
        required: true,
        message: "请输入旧密码",
        trigger: "change",
      },
    ],
  },

  function ({ formData }) {
    const r = [];
    r.push({
      value: "dma",
      label: "新密码",
      type: "password",
      rules: [
        {
          required: true,
          message: "请输入密码",
          trigger: "blur",
        },
        {
          validator(_rule, value, callback) {
            if (value && !isPassword(value)) {
              callback(new Error("密码格式不正确"));
            } else {
              callback();
            }
          },
          message: "密码应为6位以上，且不能全为数字或字母",
          trigger: ["blur"],
        },
        {
          message: "密码最少为6位",
          trigger: "blur",
          validator(_rule, value, callback) {
            if (value.length < 6) {
              callback(new Error("error"));
            } else {
              callback();
            }
          },
        },
      ],
    });
    function qrdma(value, callback) {
      if (formData.dma != value) {
        callback(new Error("error"));
      } else {
        callback();
      }
    }
    r.push({
      value: "qrdma",
      label: "确认密码",
      type: "password",
      rules: [
        {
          required: true,
          message: "请再次输入密码",
          trigger: "blur",
          validator(_rule, value, callback) {
            qrdma(value, callback);
          },
        },
      ],
    });

    return r;
  },
];
export default {
  searchjson,
  Uaddjson,
  Uedtjson,
  Udmaedt,
};
